package com.example.controller;

import com.example.pojo.User;
import com.example.service.UserService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;

import java.util.List;

/**
 * @program: springboot_course
 * @description:
 * @author: ChenZhiXiang
 * @create: 2019-06-12 17:41
 **/
@RestController
public class UserController {

    @Autowired
    private UserService userService;

    @GetMapping("/del")
    public void del(@RequestParam("id") Integer id){
        userService.delete(id);
    }

    @GetMapping("/up")
    public User up(@RequestParam("id") Integer id,@RequestParam("name") String name){
        User user = new User();
        user.setId(id);
        user.setName(name);
        return userService.update(user);
    }

    @GetMapping("/findById")
    public User findById(@RequestParam("id") Integer id){
        return userService.findById(id);
    }

    @GetMapping("/getUserList")
    public List<User> getUserList(){
        return userService.getUserList();
    }

    @GetMapping("/save")
    public Integer save(@RequestParam("name") String name){
        User user = new User();
        user.setName(name);
        return userService.save(user);
    }
}
